package com.oa.msg;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class PushMessageTimer {
    //@Autowired
    //MessageMapper messageMapper;
    
    private static CometConnectListener cometUtil = null;
    public void doit(){
    	System.out.println("任务调度发送消息===========1111111111============");
        if(cometUtil == null){
            cometUtil = new CometConnectListener();
        }
        List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
        int msgCount = 10;
        String userName="张无忌";
        double money = 200;
        try {
            //String userId = (String) request.getSession().getAttribute("currentUserId");//精准推送需要获取前端保存到session的用户id
            //resultList = messageMapper.getUnReadMessageList(null);
            //msgCount   = messageMapper.getUnReadMessageCount(null);
        	//String json = "{\"用户名\":\"" + userName +"\"" +",\"金额\":" + 200 +  "}";
            Map<String,Object> data = new HashMap<String,Object>();
            data.put("用户名", userName);
            data.put("金额", money);
            resultList.add(data);
            //推送消息
            Comet comet = new Comet();
            comet.setUserId("4");
            comet.setMsgCount(String.valueOf(msgCount));
            comet.setMsgData(resultList);
            System.out.println("任务调度发送消息===========2222222============"+resultList);
            cometUtil.pushTo(comet);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    }
}
/*
//所有客户端推送：

Comet comet = new Comet();
comet.setMsgCount(String.valueOf(msgCount));
comet.setMsgData(resultList);

new CometUtil()..pushToAll(comet);

//精准推送给某个客户端

Comet comet = new Comet();
comet.setUserId("1");//前端到session中的用户id

comet.setMsgCount(String.valueOf(msgCount));
comet.setMsgData(resultList);

new CometUtil()..pushTo(comet); 
*/



